package com.system.xingzhi.controller;

import com.system.xingzhi.model.ReturnData;
import com.system.xingzhi.model.RolePermission;
import com.system.xingzhi.service.RolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController("/rolePermission")
@CrossOrigin
@Api(value = "/rolePermission",tags = {"角色"},description = "角色管理")
public class RolePermissionController {

    @Autowired
    private RolePermissionService rolePermissionService;

    @PostMapping(value="/addRolePermission")
    @ApiOperation(notes = "增加角色权限",value = "增加角色权限")
    public ReturnData addUser(@ModelAttribute RolePermission rolePermission){
        return  rolePermissionService.insert(rolePermission);
    }

    @PostMapping(value="/deleteRolePermission")
    @ApiOperation(notes = "删除角色权限",value = "删除角色权限")
    public ReturnData deleteUser(@ApiParam(name = "rolePermissionId",value = "角色权限id") @RequestParam("rolePermissionId") String rolePermissionId){
        return  rolePermissionService.deleteByPrimaryKey(rolePermissionId);
    }

    @PostMapping(value="/updateRolePermission")
    @ApiOperation(notes = "更新角色权限",value = "更新角色权限")
    public ReturnData updateUser(@ModelAttribute RolePermission rolePermission){
        return  rolePermissionService.updateByPrimaryKey(rolePermission);
    }
    @PostMapping(value="/selectByRoleId")
    @ApiOperation(notes = "通过角色id查询角色权限节点",value = "通过角色id查询角色权限节点")
    public ReturnData selectByRoleId(@ApiParam(name = "roleId",value = "角色id") @RequestParam("roleId") String roleId){
        return  rolePermissionService.selectByRoleId(roleId);
    }

    @PostMapping(value="/getOtherChildNode")
    @ApiOperation(notes = "通过节点信息获得子节点信息",value = "通过节点信息获得子节点信息")
    public ReturnData getOtherChildNode(
            @ApiParam(name = "nodeId",value = "节点id") @RequestParam("nodeId") String nodeId
            ){
        return  rolePermissionService.getOtherChildNode(nodeId);
    }

    @PostMapping(value="/addChildNode")
    @ApiOperation(notes = "通过节点信息获得子节点信息",value = "通过节点信息获得子节点信息")
    public ReturnData addChildNode(
            @ApiParam(name = "nodeId",value = "节点id") @RequestParam("nodeId") String nodeId,
            @ApiParam(name = "id",value = "id") @RequestParam("id") String id,
            @ApiParam(name = "nodeType",value = "节点Type") @RequestParam("nodeType") String nodeType,
            @ApiParam(name = "value",value = "value") @RequestParam("value") String value
    ){
        return  rolePermissionService.addChildNode(nodeId,id,nodeType,value);
    }
    @PostMapping(value="/deleteNode")
    @ApiOperation(notes = "通过节点信息获得子节点信息",value = "通过节点信息获得子节点信息")
    public ReturnData deleteNode(
            @ApiParam(name = "nodeId",value = "节点id") @RequestParam("nodeId") String nodeId

    ){
        return  rolePermissionService.deleteByPrimaryKey(nodeId);
    }

    @PostMapping(value="/getRouterTableByRole")
    @ApiOperation(notes = "查看当前角色路由表",value = "查看当前角色路由表")
    public ReturnData getRouterTableByRole(
            @ApiParam(name = "roleId",value = "节点id") @RequestParam("roleId") String roleId

    ){
        return  rolePermissionService.getRouterTableByRole(roleId);
    }
}
